package com.zhipu.resetbalance.ui;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import com.blankj.utilcode.util.ActivityUtils;
import com.google.gson.Gson;


public abstract class BaseActivity<V extends ViewDataBinding> extends AppCompatActivity {
    protected Context mContext;
    protected V binding;
    protected Gson mGson;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        //初始化GSON
        mGson = new Gson();
        /**
         * 全屏
         */
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        /**
         * 保持亮屏
         */
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

        //创建
        initCreate();
        //页面接受的参数方法
        initParam();
        //页面数据初始化方法
        //私有的初始化Databinding和ViewModel方法
        initViewDataBinding(savedInstanceState);
        //VM
        initViewModel();
        //
        initView();
        //
        initData();

        //页面事件监听的方法，一般用于ViewModel层转到View层的事件注册
        initViewObservable();

    }

    public void initCreate(){

    }


    public void initParam() {

    }

    /**
     * 初始化根布局
     *
     * @return 布局layout的id
     */
    public abstract int initContentView(Bundle savedInstanceState);

    /**
     * 注入绑定
     */
    private void initViewDataBinding(Bundle savedInstanceState) {
        binding = DataBindingUtil.setContentView(this, initContentView(savedInstanceState));
    }

    public void initViewModel() {

    }
    public void initView() {

    }

    public void initData() {

    }

    public void initViewObservable() {

    }




    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
//        if (hasFocus && Build.VERSION.SDK_INT >= 19) {
//            View gameView = this.getWindow().getDecorView();
//            gameView.setSystemUiVisibility(
//                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
//                            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
//                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
//                            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
//                            | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
//                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
//
//        }
    }



    @Override
    protected void onDestroy() {
        super.onDestroy();

    }
}
